home *** CD-ROM | disk | FTP | other *** search
/ Tricks of the Mac Game Programming Gurus / TricksOfTheMacGameProgrammingGurus.iso / More Source / C⁄C++ / Chess++ 3.0.1 / source / CAboutChessBox.cp < prev    next >
Text File  |  1993-05-26  |  8KB  |  324 lines

  1. ////////////
  2. //
  3. //    CAboutChessBox.cp
  4. //
  5. //    The Chess++ About Box Class
  6. //
  7. //    SUPERCLASS = CDirector
  8. //    Copyright © 1993 Steven J. Bushell. All rights reserved.
  9. //
  10. ////////////
  11.  
  12. #include <CBartender.h>
  13. #include <CDecorator.h>
  14. #include <CApplication.h>
  15. #include "CAboutChessBox.h"
  16. #include <CWindow.h>
  17. #include <CBitMap.h>
  18. #include <CBitMapPane.h>
  19.  
  20. #include <QDOffscreen.h>
  21. #include <Stdlib.h>
  22. #include <Sane.h>
  23. #include <math.h>
  24. #include <FixMath.h>
  25.  
  26. #define WINDChessSplashScreen 520
  27.  
  28. /*** Global Variables ***/
  29.  
  30. extern    CApplication    *gApplication;        /* Global Application object        */
  31. extern    CBartender        *gBartender;        /* Manages all menus                */
  32. extern    CBureaucrat        *gGopher;            /* First in line to get commands    */
  33. extern    CDesktop        *gDesktop;
  34. extern    CDecorator        *gDecorator;
  35.  
  36. /**** C O N S T R U C T I O N / D E S T R U C T I O N   M E T H O D S ****/
  37.  
  38. void    CAboutChessBox::IAboutChessBox(CDirectorOwner *aSupervisor)
  39. {    
  40.     FlashMenuBar(1);
  41.     CDirector::IDirector(aSupervisor);    /* Initialize superclass            */
  42.     itsWindow = new(CWindow);
  43.     itsWindow->IWindow(WINDChessSplashScreen, true, gDesktop, this);
  44.  
  45.     GetDateTime((unsigned long *)&randSeed);
  46.     switch((Random() % 2) + 1) {
  47.         case 0:
  48.             DoAboutChess();
  49.             break;
  50.         case 1:
  51.             DoAboutChessGradualWiggle();
  52.             break;
  53.         case 2:
  54.         default:
  55.             DoAboutChessWiggle();
  56.             break;
  57.     }
  58. }
  59.  
  60.  
  61. static CGrafPtr    savedGWorld;
  62. static GDHandle    savedGDevice;
  63.  
  64. static void EnterGWorldMode(GWorldPtr theNewGWorld)
  65. {
  66.     GetGWorld(&savedGWorld,&savedGDevice);
  67.     SetGWorld(theNewGWorld,nil);
  68. }
  69.  
  70. static void ExitGWorldMode(void)
  71. {
  72.     SetGWorld(savedGWorld,savedGDevice);
  73. }
  74.         
  75. void    CAboutChessBox::DoAboutChessWiggle(void)
  76. {
  77.     register        i;
  78.     PicHandle        thePict;
  79.     Rect            picRect,blitRect,destRect,letRect[20];
  80.     GWorldPtr        picWorld,bufWorld;
  81.     PixMapHandle    picPmh,bufPmh;
  82.     OSErr            qdErr;
  83.  
  84.     thePict = GetPicture(WINDChessSplashScreen);
  85.     picRect = (*thePict)->picFrame;
  86.  
  87.     qdErr = NewGWorld(&picWorld,8,&picRect,nil,nil,0);
  88.     qdErr = NewGWorld(&bufWorld,8,&picRect,nil,nil,0);
  89.  
  90.     itsWindow->ChangeSize(picRect.right-picRect.left,picRect.bottom-picRect.top);
  91.     gDecorator->CenterWindow(itsWindow);
  92.     itsWindow->Show();
  93.  
  94.     itsWindow->Prepare();
  95.     SetOrigin(picRect.left,picRect.top);
  96.     ClipRect(&picRect);
  97.     DrawPicture(thePict,&picRect);    
  98.  
  99.     EnterGWorldMode(picWorld);
  100.     SetOrigin(picRect.left,picRect.top);
  101.     ClipRect(&picRect);
  102.     DrawPicture(thePict,&picRect);    
  103.     ExitGWorldMode();
  104.  
  105.     EnterGWorldMode(bufWorld);
  106.     SetOrigin(picRect.left,picRect.top);
  107.     ClipRect(&picRect);
  108.     EraseRect(&picRect);
  109.     ExitGWorldMode();
  110.  
  111.     ReleaseResource((Handle)thePict);
  112.     TextMode(srcCopy);
  113.  
  114.     picPmh = GetGWorldPixMap(picWorld);
  115.     bufPmh = GetGWorldPixMap(bufWorld);
  116.     LockPixels(picPmh);
  117.     LockPixels(bufPmh);
  118.     
  119.     SetRect(&letRect[0],50,100,113,216);    //    C
  120.     SetRect(&letRect[1],116,92,183,216);    //    h
  121.     SetRect(&letRect[2],184,126,238,216);    //    e
  122.     SetRect(&letRect[3],236,128,285,216);    //    s
  123.     SetRect(&letRect[4],285,128,332,216);    //    s
  124.     SetRect(&letRect[5],332,130,395,216);    //    +
  125.     SetRect(&letRect[6],396,130,458,216);    //    +
  126.  
  127.     SetRect(&picRect,24,88,472,226);
  128.  
  129.     while(!Button())
  130.     {
  131.         CopyBits((BitMap *)(*picPmh),(BitMap *)(*bufPmh),
  132.                     &picRect,&picRect,srcCopy,nil);
  133.         EnterGWorldMode(bufWorld);
  134.         for (i=0;i<7;i++)
  135.         {
  136.             destRect = letRect[i];
  137.             OffsetRect(&destRect,Random()/3000,Random()/3000);
  138.             CopyBits((BitMap *)(*picPmh),(BitMap *)(*bufPmh),
  139.                         &letRect[i],&destRect,adMin,nil);
  140.         }
  141.         ExitGWorldMode();
  142.         CopyBits((BitMap *)(*bufPmh),&itsWindow->macPort->portBits,
  143.                     &picRect,&picRect,srcCopy,nil);                    
  144.     }
  145.  
  146.     UnlockPixels(picPmh);
  147.     UnlockPixels(bufPmh);
  148.  
  149.     DisposeGWorld(picWorld);
  150.     DisposeGWorld(bufWorld);
  151.  
  152.     while(!Button())
  153.         ;
  154. }
  155.  
  156. void    CAboutChessBox::DoAboutChessGradualWiggle(void)
  157. {
  158.     register        i,div;
  159.     PicHandle        thePict;
  160.     Rect            picRect,blitRect,destRect,letRect[20];
  161.     GWorldPtr        picWorld,bufWorld;
  162.     PixMapHandle    picPmh,bufPmh;
  163.     OSErr            qdErr;
  164.  
  165.     thePict = GetPicture(WINDChessSplashScreen);
  166.     picRect = (*thePict)->picFrame;
  167.  
  168.     qdErr = NewGWorld(&picWorld,8,&picRect,nil,nil,0);
  169.     qdErr = NewGWorld(&bufWorld,8,&picRect,nil,nil,0);
  170.  
  171.     itsWindow->ChangeSize(picRect.right-picRect.left,picRect.bottom-picRect.top);
  172.     gDecorator->CenterWindow(itsWindow);
  173.     itsWindow->Show();
  174.  
  175.     itsWindow->Prepare();
  176.     SetOrigin(picRect.left,picRect.top);
  177.     ClipRect(&picRect);
  178.     DrawPicture(thePict,&picRect);    
  179.  
  180.     EnterGWorldMode(picWorld);
  181.     SetOrigin(picRect.left,picRect.top);
  182.     ClipRect(&picRect);
  183.     DrawPicture(thePict,&picRect);    
  184.     ExitGWorldMode();
  185.  
  186.     EnterGWorldMode(bufWorld);
  187.     SetOrigin(picRect.left,picRect.top);
  188.     ClipRect(&picRect);
  189.     EraseRect(&picRect);
  190.     ExitGWorldMode();
  191.  
  192.     ReleaseResource((Handle)thePict);
  193.     TextMode(srcCopy);
  194.  
  195.     picPmh = GetGWorldPixMap(picWorld);
  196.     bufPmh = GetGWorldPixMap(bufWorld);
  197.     LockPixels(picPmh);
  198.     LockPixels(bufPmh);
  199.     
  200.     SetRect(&letRect[0],50,100,113,216);    //    C
  201.     SetRect(&letRect[1],116,92,183,216);    //    h
  202.     SetRect(&letRect[2],184,126,238,216);    //    e
  203.     SetRect(&letRect[3],236,128,285,216);    //    s
  204.     SetRect(&letRect[4],285,128,332,216);    //    s
  205.     SetRect(&letRect[5],332,130,395,216);    //    +
  206.     SetRect(&letRect[6],396,130,458,216);    //    +
  207.  
  208.     div = 35000;
  209.     while(!Button())
  210.     {
  211.         CopyBits((BitMap *)(*picPmh),(BitMap *)(*bufPmh),
  212.                     &picRect,&picRect,srcCopy,nil);
  213.         EnterGWorldMode(bufWorld);
  214.         for (i=0;i<7;i++)
  215.         {
  216.             destRect = letRect[i];
  217.             OffsetRect(&destRect,Random()/div,Random()/div);
  218.             if (div > 500)
  219.                 div -= 50;
  220.             CopyBits((BitMap *)(*picPmh),(BitMap *)(*bufPmh),
  221.                         &letRect[i],&destRect,adMin,nil);
  222.         }
  223.         ExitGWorldMode();
  224.         CopyBits((BitMap *)(*bufPmh),&itsWindow->macPort->portBits,
  225.                     &picRect,&picRect,srcCopy,nil);                    
  226.     }
  227.  
  228.     UnlockPixels(picPmh);
  229.     UnlockPixels(bufPmh);
  230.  
  231.     DisposeGWorld(picWorld);
  232.     DisposeGWorld(bufWorld);
  233.  
  234.     while(!Button())
  235.         ;
  236. }
  237.  
  238. void    CAboutChessBox::DoAboutChess(void)
  239. {
  240.     register        i,div,divInc=0;
  241.     PicHandle        thePict;
  242.     Rect            picRect,blitRect,destRect,letRect[20];
  243.     GWorldPtr        picWorld,bufWorld;
  244.     PixMapHandle    picPmh,bufPmh;
  245.     OSErr            qdErr;
  246.     short            centerh,centerv;
  247.  
  248.     thePict = GetPicture(WINDChessSplashScreen);
  249.     picRect = (*thePict)->picFrame;
  250.  
  251.     qdErr = NewGWorld(&picWorld,8,&picRect,nil,nil,0);
  252.     qdErr = NewGWorld(&bufWorld,8,&picRect,nil,nil,0);
  253.  
  254.     itsWindow->ChangeSize(picRect.right-picRect.left,picRect.bottom-picRect.top);
  255.     gDecorator->CenterWindow(itsWindow);
  256.     itsWindow->Show();
  257.  
  258.     itsWindow->Prepare();
  259.     SetOrigin(picRect.left,picRect.top);
  260.     ClipRect(&picRect);
  261.  
  262.     EnterGWorldMode(picWorld);
  263.     SetOrigin(picRect.left,picRect.top);
  264.     ClipRect(&picRect);
  265.     DrawPicture(thePict,&picRect);    
  266.     ExitGWorldMode();
  267.  
  268.     EnterGWorldMode(bufWorld);
  269.     SetOrigin(picRect.left,picRect.top);
  270.     ClipRect(&picRect);
  271.     EraseRect(&picRect);
  272.     ExitGWorldMode();
  273.  
  274.     ReleaseResource((Handle)thePict);
  275.     TextMode(srcCopy);
  276.  
  277.     picPmh = GetGWorldPixMap(picWorld);
  278.     bufPmh = GetGWorldPixMap(bufWorld);
  279.     LockPixels(picPmh);
  280.     LockPixels(bufPmh);
  281.     
  282.     SetRect(&letRect[0],50,100,113,216);    //    C
  283.     SetRect(&letRect[1],116,92,183,216);    //    h
  284.     SetRect(&letRect[2],184,126,238,216);    //    e
  285.     SetRect(&letRect[3],236,128,285,216);    //    s
  286.     SetRect(&letRect[4],285,128,332,216);    //    s
  287.     SetRect(&letRect[5],332,130,395,216);    //    +
  288.     SetRect(&letRect[6],396,130,458,216);    //    +
  289.     SetRect(&letRect[7],80,46,404,90);        //    Symantec's
  290.     SetRect(&letRect[8],84,230,136,274);    //    by
  291.     SetRect(&letRect[9],144,230,248,266);    //    Steve
  292.     SetRect(&letRect[10],254,230,396,264);    //    Bushell
  293.  
  294.     centerh = (picRect.right - picRect.left) / 2 + picRect.left;
  295.     centerv = (picRect.bottom - picRect.top) / 2 + picRect.top;
  296.     div = 200;
  297.     while(!Button())
  298.     {
  299.         EnterGWorldMode(bufWorld);
  300.         EraseRect(&picRect);
  301.         for (i=0;i<11;i++)
  302.         {
  303.             destRect = letRect[i];
  304.             OffsetRect(&destRect,(centerh - (destRect.right - destRect.left)/2 - destRect.left)*200L/div,
  305.                                 (centerv - (destRect.bottom - destRect.top)/2 - destRect.top)*200L/div);
  306.             CopyBits((BitMap *)(*picPmh),(BitMap *)(*bufPmh),
  307.                         &letRect[i],&destRect,adMin,nil);
  308.         }
  309.         if (div < 30000)
  310.             div+=divInc++;
  311.         ExitGWorldMode();
  312.         CopyBits((BitMap *)(*bufPmh),&itsWindow->macPort->portBits,
  313.                     &picRect,&picRect,srcCopy,nil);                    
  314.     }
  315.  
  316.     UnlockPixels(picPmh);
  317.     UnlockPixels(bufPmh);
  318.  
  319.     DisposeGWorld(picWorld);
  320.     DisposeGWorld(bufWorld);
  321.  
  322.     while(!Button())
  323.         ;
  324. }